﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Superstore.Vender.Models;
using System.Web.Configuration;
using Senparc.Weixin.MP.Helpers;
using Senparc.Weixin.MP.CommonAPIs;

namespace Superstore.Vender.Controllers
{
    public class HomeController : UserInfoController
    {
        public ActionResult Index(string code, string state, string type)
        {
            if (!string.IsNullOrEmpty(type))
            {
                ViewBag.Type = 0;
                #region JSSDK
                //获取时间戳
                var timestamp = JSSDKHelper.GetTimestamp();
                //获取随机码
                var nonceStr = JSSDKHelper.GetNoncestr();
                string ticket = JsApiTicketContainer.TryGetTicket(AppId, AppSecret);
                JSSDKHelper jsHelper = new JSSDKHelper();
                //获取签名
                var signature = jsHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri);

                ViewData["AppId"] = AppId;
                ViewData["Timestamp"] = timestamp;
                ViewData["NonceStr"] = nonceStr;
                ViewData["Signature"] = signature;
                #endregion
            }
            else
            {
                ViewBag.Type = 1;
            }
            
            return base.check(code, state, "/Home/Index?type=open");
        }
        public ActionResult Home(string code, string state)
        {
            return base.check(code, state, "/Home/Home");
        }
        [HttpPost]
        public PartialViewResult PreHome()
        {
            return PartialView("preHome");
        }
        [HttpPost]
        public PartialViewResult _Home()
        {
            return PartialView("home");
        }

        [HttpPost]
        public PartialViewResult VenderLayout()
        {
            return PartialView("venderLayout");
        }

        [HttpPost]
        public PartialViewResult NoVenderLayout()
        {
            return PartialView("noVenderLayout");
        }

        [HttpPost]
        public PartialViewResult ShowMenuList(List<MenuInfo> main_menu_list)
        {
            if (main_menu_list != null && main_menu_list.Count > 0)
            {
                return PartialView("ShowMenuList", main_menu_list);
            }
            return PartialView("ShowMenuList");
        }

        public PartialViewResult Shopping(List<ShoppingCartGoodsInfo> shoppingsList)
        {
            if (shoppingsList != null && shoppingsList.Count > 0)
            {
                return PartialView("Shopping", shoppingsList);
            }
            return PartialView("Shopping");
        }
    }
}